package edu.xust.dao.impl;

import edu.xust.config.Repository;
import edu.xust.config.Resource;
import edu.xust.dao.AdminDao;
import edu.xust.entity.Admin;
import edu.xust.entity.AdminExample;
import edu.xust.mapper.AdminMapper;
import edu.xust.page.PageInfo;

import java.util.List;

/**
 * @auther: zhangxin
 * @Description:
 */
@Repository("adminDao")
public class AdminDaoImpl implements AdminDao {

    @Resource
    AdminMapper adminMapper;

    @Override
    public List<Admin> getAdminByPage(PageInfo pageInfo) throws Exception {
        AdminExample adminExample = new AdminExample();
        long l = adminMapper.countByExample(null);
        pageInfo.setItemCount((int)l);
        adminExample.setOffset(pageInfo.getOffset());
        adminExample.setLimit(pageInfo.getPageSize());
        return adminMapper.selectByExample(adminExample);
    }

    @Override
    public List<Admin> selectByExample(AdminExample example) {
        return adminMapper.selectByExample(example);
    }

    @Override
    public Integer addAdmin(Admin admin) {
        return adminMapper.insert(admin);
    }

    @Override
    public Integer editAdmin(Admin admin) {
        return adminMapper.updateByPrimaryKey(admin);
    }

    @Override
    public Admin getAdminById(Integer adId) {
        return adminMapper.selectByPrimaryKey(adId);
    }

    @Override
    public Integer deleteAdminById(Integer adid) {
        return adminMapper.deleteByPrimaryKey(adid);
    }

    /**
     * @auther: zhangxin
     * @Description:
     */
    @Repository("adminDao")
    public static class StationDaoImpl implements AdminDao {

        @Resource
        AdminMapper adminMapper;

        @Override
        public List<Admin> getAdminByPage(PageInfo pageInfo) throws Exception {
            AdminExample adminExample = new AdminExample();
            long l = adminMapper.countByExample(null);
            pageInfo.setItemCount((int)l);
            adminExample.setOffset(pageInfo.getOffset());
            adminExample.setLimit(pageInfo.getPageSize());
            return adminMapper.selectByExample(adminExample);
        }

        @Override
        public List<Admin> selectByExample(AdminExample example) {
            return adminMapper.selectByExample(example);
        }

        @Override
        public Integer addAdmin(Admin admin) {
            return adminMapper.insert(admin);
        }

        @Override
        public Integer editAdmin(Admin admin) {
            return adminMapper.updateByPrimaryKey(admin);
        }

        @Override
        public Admin getAdminById(Integer adId) {
            return adminMapper.selectByPrimaryKey(adId);
        }

        @Override
        public Integer deleteAdminById(Integer adid) {
            return adminMapper.deleteByPrimaryKey(adid);
        }
    }
}
